package 创建型模式.单例模式.懒汉式;

/**
 * 懒汉式:只有在需要用的时候才会实例化对象，线程不安全
 */
public class User 
{
	private static User user;

	public static User getUser() 
	{
		if(user == null)
		{
			user = new User();
		}
		return user;
	}

	//静态内部类创建
	private static class SingletonHolder
	{
		private static final User INSTANCE = new User();
	}

	public static User getInstance()
	{
		return SingletonHolder.INSTANCE; // 第一次调用时才加载内部类
	}
}